#include <utils/bank.h>


namespace AccountManagerUtils {
	
//! Default constructor
Bank::Bank() : name_(""), phone_number_(""), fax_number_("") {}

//! Copy constructor
Bank::Bank(const Bank& rhs) :
	name_(rhs.name_), address_(rhs.address_), phone_number_(rhs.phone_number_), fax_number_(rhs.fax_number_) {}

//! Constructor from a name
Bank::Bank(const String& name) : name_(name), phone_number_(""), fax_number_("") {}

//! Constructor from a name and an address
Bank::Bank(const String& name, const Address& address) :
	name_(name), address_(address), phone_number_(""), fax_number_("") {}

//! Constructor from a name, an address, a phone number and a fax number
Bank::Bank(const String& name, const Address& address, const String& phone_number, const String& fax_number) :
	name_(name), address_(address), phone_number_(phone_number), fax_number_(fax_number) {}

//! Destructor
Bank::~Bank() {}

//! Copy constructor
Bank& Bank::operator=(const Bank& rhs) {
	if ( &rhs != this ) {
		name_ = rhs.name_;
		address_ = rhs.address_;
		phone_number_ = rhs.phone_number_;
		fax_number_ = rhs.fax_number_;
	}
	return *this;
}

//! Comparison operator
/*!
 *  This operator only compares the name, but ignores the description
 */
bool Bank::operator==(const Bank& rhs) const {
	return ( name_ == rhs.name_ );
}

//! Difference operator
/*!
 *  This operator only compares the name, but ignores other fields
 */
bool Bank::operator!=(const Bank& rhs) const {
	return ( name_ != rhs.name_ );
}

//! Accessor to the name of the bank (read-write)
String& Bank::name() {
	return name_;
}

//! Accessor to the name of the bank (read only)
const String& Bank::name() const {
	return name_;
}

//! Accessor to the address of the bank (read-write)
Address& Bank::address() {
	return address_;
}

//! Accessor to the address of the bank (read only)
const Address& Bank::address() const {
	return address_;
}

//! Accessor to the name of the bank (read-write)
String& Bank::phone_number() {
	return phone_number_;
}

//! Accessor to the name of the bank (read only)
const String& Bank::phone_number() const {
	return phone_number_;
}

//! Accessor to the fax number of the bank (read-write)
String& Bank::fax_number() {
	return fax_number_;
}

//! Accessor to the fax number of the bank (read only)
const String& Bank::fax_number() const {
	return fax_number_;
}

//===========================================================

//! Initialize the bank lib instance
BankLib* BankLib::instance_ = NULL;

//! Find a bank with given name, if any
const Bank* BankLib::find_bank(const String& name) {
	QSet<Bank>::iterator it = instance()->banks_.find( name );
	if ( it == instance()->banks_.end() ) {
		return NULL;
	}
	return &(*it);
}

//! Get the list of banks
const Set<Bank>& BankLib::banks() {
	return instance()->banks_;
}

//! Destructor
BankLib::~BankLib() {}

//! Constructor
BankLib::BankLib() {}

//! Find or create the instance of BankLib
BankLib* BankLib::instance() {
	if ( instance_ == NULL ) {
		instance_ = new BankLib();
	}
	return instance_;
}

} // namespace AccountManagerUtils

